<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk">

    <f:view>
        <f:loadBundle var="text" basename="#{contactList.bundleName}"/>
        <head>
            <title>#{text['contactList.title']}</title>
            <meta name="heading" content="#{text['contactList.heading']}"/>
            <meta name="menu" content="CatalogsMenu"/>
        </head>
        <body id="contactList">
        <h:form id="editcontact">

            <h:commandButton value="#{text['button.search']}"  action="#{contactList.execute}" id="search" styleClass="button" style="margin-left: 5px"/>
            <h:commandButton value="#{text['button.add']}" action="#{contactForm.add}" id="add" immediate="true" styleClass="button"/>
            <h:commandButton value="#{text['button.done']}" action="mainMenu" id="close" immediate="true" styleClass="button" style="margin-left: 5px"/>            

            <h:panelGroup>
                <table>
                    <tr>
                        <td>
                        <t:htmlTag value="div">
                            <h:outputLabel styleClass="desc" for="firstName" value="#{text['contact.firstName']}"/>
                            <h:inputText styleClass="text medium" id="firstName" value="#{contactList.firstName}"/>
                            <t:message for="firstName" styleClass="fieldError"/>
                        </t:htmlTag>
                        </td>
                        <td>
                        <t:htmlTag value="div">
                            <h:outputLabel styleClass="desc" for="lastName" value="#{text['contact.lastName']}"/>
                            <h:inputText styleClass="text medium" id="lastName" value="#{contactList.lastName}"/>
                            <t:message for="lastName" styleClass="fieldError"/>
                        </t:htmlTag>
                        </td>
                    </tr>
                </table>
            </h:panelGroup>
            
            <!-- Error from this table is caused by http://issues.apache.org/jira/browse/TOMAHAWK-466 -->
            <t:dataTable id="contacts" var="contact" style="margin-top: 10px"
                         value="#{contactList.contacts}" rows="25" sortColumn="#{contactList.sortColumn}"
                         sortAscending="#{contactList.ascending}" styleClass="scrollerTable table"
                         headerClass="standardTable_Header" rowClasses="standardTable_Row1,standardTable_Row2"
                         columnClasses="standardTable_Column,standardTable_Column,standardTable_Column,standardTable_Column,standardTable_ColumnCentered">

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="id" arrow="true">
                            <h:outputText value="#{text['contact.id']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:commandLink action="#{contactForm.edit}" value="#{contact.id}">
                        <f:param name="id" value="#{contact.id}"/>
                        <f:param name="from" value="list"/>
                    </h:commandLink>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="firstName" arrow="true">
                            <h:outputText value="#{text['contact.firstName']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{contact.firstName}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="lastName" arrow="true">
                            <h:outputText value="#{text['contact.lastName']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{contact.lastName}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="company" arrow="true">
                            <h:outputText value="#{text['contact.company']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{contact.company.description}" escape="true"/>
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <t:commandSortHeader columnName="phone" arrow="true">
                            <h:outputText value="#{text['contact.phone']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{contact.phone}" escape="true"/>
                </t:column>
            </t:dataTable>

            <ui:include src="/common/tableFooter.xhtml">
                <ui:param name="tableName" value="contacts"/>
            </ui:include>

            <script type="text/javascript">
                highlightTableRows("editcontact:contacts");
            </script>

        </h:form>
    </body>
</f:view>
</html>